const _my = require("../../__antmove/api/index.js")(my);
const wx = _my;
let WebIM = require("../../utils/WebIM")["default"];
let __test_account__, __test_psword__;
let disp = require("../../utils/broadcast");


if (my.isIDE) {
  __test_account__ = "user1";
  __test_psword__ = "123";
}

Page({
  data: {
    name: "",
    psd: "",
    grant_type: "password"
  },
  onLoad: function () {
    const me = this;
    let app = getApp();
    new app.ToastPannel.ToastPannel();
    disp.on("em.xmpp.error.tokenErr", function () {
      me.toastFilled("token错误、token过期或者未授权");
    });
  },
  bindUsername: function (e) {
    this.setData({
      name: e.detail.value
    });
  },
  bindPassword: function (e) {
    this.setData({
      psd: e.detail.value
    });
  },
  onFocusPsd: function () {
    this.setData({
      psdFocus: "psdFocus"
    });
  },
  onBlurPsd: function () {
    this.setData({
      psdFocus: ""
    });
  },
  onFocusName: function () {
    this.setData({
      nameFocus: "nameFocus"
    });
  },
  onBlurName: function () {
    this.setData({
      nameFocus: ""
    });
  },
  login: function () {
    if (!__test_account__ && this.data.name == "") {
      this.toastFilled("请输入用户名！");
      return;
    } else if (!__test_account__ && this.data.psd == "") {
      this.toastFilled("请输入token！");
      return;
    }
    console.log('用户名密码登录', this.data.name);
    wx.setStorage({
      key: "myUsername",
      data: __test_account__ || this.data.name.toLowerCase()
    });
    getApp().conn.open({
      apiUrl: WebIM.config.apiURL,
      user: __test_account__ || this.data.name.toLowerCase(),
      pwd: __test_psword__ || this.data.psd,
      //accessToken: __test_psword__ || this.data.psd,
      //grant_type: this.data.grant_type,
      appKey: WebIM.config.appkey
    });
  },
  antmoveAction: function () {
    //执行时动态赋值，请勿删除
  },
});